package com.lijin.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lijin.Exception.TimeParseException;
import com.lijin.common.HttpRequest;
import com.lijin.domain.dto.CurrentData;
import com.lijin.domain.dto.CurrentResult;
import com.lijin.domain.dto.Data500;
import com.lijin.domain.dto.LebaData;
import com.lijin.domain.dto.LebadataList;
import com.lijin.domain.dto.QuanqiuData;
import com.lijin.domain.dto.ReturnData500;
import com.lijin.domain.dto.ReturnHungData;
import com.lijin.domain.dto.ReturnJSData;
import com.lijin.domain.dto.ReturnLHCdata;
import com.lijin.domain.json.LotteryData;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.boot.json.GsonJsonParser;

/**
 * Created by abbott-jx on 2017/9/18.
 */
@Slf4j
public class JsoupUtil {

  public static LotteryData CaiPiaoYun(String url, String code) throws IOException, ParseException {
    Document document = null;
    try {
      document = Jsoup.connect(url).userAgent(
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36")
          .get();
    } catch (Exception e) {
      throw e;
    }
    //kj-detail-table
    Elements elements = document.getElementsByClass("kj-detail-table");
    Element element = elements.get(0).getElementsByTag("tr").get(1);
    String expect[] = element.child(0).text().split(" ");
    String expectnew = "20" + expect[0];
    String opencode = element.child(1).child(0).text();
    LotteryData lotteryData = new LotteryData();
    for (int i = 1; i < element.child(1).children().size(); i++) {
      opencode = opencode + "," + element.child(1).child(i).text();
    }
       /* if ("HF_JSK3".equals(code) ) {
                expectnew = expectnew.substring(0, 8) + "0" + expectnew.substring(8, expectnew.length());

        }*/
    lotteryData.setCode(code);
    lotteryData.setOpentime(DataUtil.dateToString());
    if ("HF_CQKL10F".equals(code) || "HF_JXD11".equals(code) || "HF_GDKL10F".equals(code)
        || "HF_GDD11".equals(code) || "HF_SDD11".equals(code) || "HF_AHD11".equals(code)
        || "HF_TJKL10F".equals(code) || "HF_SHD11".equals(code) || "HF_BJPK10".equals(code)
        || "HF_XYFT".equals(code) || "MARK_SIX".equals(code)) {
      lotteryData.setOpencode(DataUtil.chuliCode(opencode));
    } else {
      lotteryData.setOpencode(DataUtil.chuliCodeRemove0(opencode));
    }
    lotteryData.setExpect(expectnew);
    return lotteryData;
  }

  public static LotteryData YiDingNiu(String url, String code, int a)
      throws SocketTimeoutException, IOException, ParseException {
    Document document = null;
    try {
      document = Jsoup.connect(url).userAgent(
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36")
          .get();
    } catch (Exception e) {
      throw e;
    }
    Element element = document.getElementById("tdMaxIsuse");
    String expect = document.getElementById("tdMaxIsuse").text();
    Elements elements = element.parent().children();
    String opencode = elements.get(1).text();
    LotteryData lotteryData = new LotteryData();
    if ("HF_GDKL10F".equals(code) || "HF_CQKL10F".equals(code)) {
    } else if (a != 0) {
      for (int i = 2; i <= a; i++) {
        opencode = opencode + "," + elements.get(i).text();
      }
    }
    String newexpect = null;
    if (!("X3D".equals(code) || "PL3".equals(code) || "HF_AHD11".equals(code) || "HF_GDD11"
        .equals(code) || "HF_JXD11".equals(code) || "HF_SDD11".equals(code) || "HF_SHD11"
        .equals(code))) {
      expect = expect.substring(0, 8) + "0" + expect.substring(8, expect.length());

    }
    lotteryData.setCode(code);
    lotteryData.setOpentime(DataUtil.dateToString());
    if ("HF_CQKL10F".equals(code) || "HF_JXD11".equals(code) || "HF_GDKL10F".equals(code)
        || "HF_GDD11".equals(code) || "HF_SDD11".equals(code) || "HF_AHD11".equals(code)
        || "HF_TJKL10F".equals(code) || "HF_SHD11".equals(code) || "HF_BJPK10".equals(code)
        || "HF_XYFT".equals(code) || "MARK_SIX".equals(code)) {
      lotteryData.setOpencode(DataUtil.chuliCode(opencode));
    } else {
      lotteryData.setOpencode(DataUtil.chuliCodeRemove0(opencode));
    }
    lotteryData.setExpect(expect);
    return lotteryData;
  }

  /***
   * 威尼斯人官网爬数据
   * @throws IOException
   * @throws ParseException
   */
  public List<LotteryData> wnisiren(String url, String code) throws IOException, ParseException {
    String test = HttpRequest.sendGet(url, null);
    ObjectMapper objectMapper = new ObjectMapper();
    CurrentData currentData = objectMapper.readValue(test, CurrentData.class);
    List<CurrentResult> list = currentData.getReturnData().getRows().getDataTD();
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    List<LotteryData> lotteryDatas = new ArrayList<>();
    for (CurrentResult currentResult : list) {
      LotteryData lotteryData = new LotteryData();
      String qishu = currentResult.getQishu();
      Date data = new Date();
      String year = format.format(data);
      String kjnum = "";

      if ("MARK_SIX".equals(code)) {
        Object json_test = JSONObject.toJSON(currentResult.getKjnumber());

        ReturnLHCdata lhc = objectMapper.readValue(json_test.toString(), ReturnLHCdata.class);
        kjnum = lhc.getNumber();
      } else {
        kjnum = currentResult.getKjnumber().toString();
      }
      String time = currentResult.getKjtime();
      lotteryData.setExpect(qishu);
      if ("HF_CQKL10F".equals(code) || "HF_JXD11".equals(code) || "HF_GDKL10F".equals(code)
          || "HF_GDD11".equals(code) || "HF_SDD11".equals(code) || "HF_AHD11".equals(code)
          || "HF_TJKL10F".equals(code) || "HF_SHD11".equals(code) || "HF_BJPK10".equals(code)
          || "HF_XYFT".equals(code) || "MARK_SIX".equals(code)) {
        lotteryData.setOpencode(DataUtil.chuliCode(kjnum));
      } else {
        lotteryData.setOpencode(DataUtil.chuliCodeRemove0(kjnum));
      }
      lotteryData.setOpentime(year + "-" + time + ":00");
      lotteryDatas.add(lotteryData);
    }
    return lotteryDatas;
  }

  public LotteryData jinShaYuLe(String autourl, String codeurl, String code)
      throws IOException, ParseException {
    String test = HttpRequest.sendPost(autourl, null);
    Document document = null;
    try {
      document = Jsoup.connect(codeurl).userAgent(
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36")
          .get();
    } catch (Exception e) {
      throw e;
    }
    ObjectMapper objectMapper = new ObjectMapper();
    ReturnJSData returnJSData = objectMapper.readValue(test, ReturnJSData.class);
    Elements elsements = document.getElementsByAttribute("valign");
    LotteryData lotteryData = new LotteryData();
    String time = "";
    for (Element element : elsements) {
      if (element.text().equals(returnJSData.getNumbers().toString())) {
        time = element.nextElementSibling().text();
        break;
      }
    }
    if (time == null) {
      throw new TimeParseException();
    }
    lotteryData.setOpentime(time);
    if ("HF_CQKL10F".equals(code) || "HF_JXD11".equals(code) || "HF_GDKL10F".equals(code)
        || "HF_GDD11".equals(code) || "HF_SDD11".equals(code) || "HF_AHD11".equals(code)
        || "HF_TJKL10F".equals(code) || "HF_SHD11".equals(code) || "HF_BJPK10".equals(code)
        || "HF_XYFT".equals(code) || "MARK_SIX".equals(code)) {
      lotteryData.setOpencode(DataUtil.chuliCode(DataUtil.text(returnJSData.getHm())));
    } else {
      lotteryData.setOpencode(DataUtil.chuliCodeRemove0(DataUtil.text(returnJSData.getHm())));
    }
    if ("HF_GDKL10F".equals(code)) {
      String expect = returnJSData.getNumbers().toString();
      expect = expect.substring(0, 8) + "0" + expect.substring(8, expect.length());
      lotteryData.setExpect(expect);
    } else {

      lotteryData.setExpect(returnJSData.getNumbers().toString());
    }
    return lotteryData;
  }

  /**
   * 皇官彩
   */
  public List<LotteryData> huangCai(String url, String code)
      throws ParseException, SocketTimeoutException {
    String test = HttpRequest.sendGet(url, null);
    //Document document=Jsoup.connect("https://www.hgw0081.com/NewLottery2/History/%E6%B1%9F%E8%A5%BF11%E9%80%895").userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36").get();
    //ObjectMapper objectMapper=new ObjectMapper();
    // ReturnHungDatas returnHungDatas= objectMapper.readValue(test,ReturnHungDatas.class);
    List<ReturnHungData> list = JSON.parseArray(test, ReturnHungData.class);
    List<LotteryData> lotterys = new ArrayList<>();
    for (ReturnHungData returnHungData : list) {
      LotteryData lotteryData = new LotteryData();
      lotteryData.setExpect(returnHungData.getButchNo());
      lotteryData.setOpentime(DataUtil.Data1ToString(returnHungData.getPublishDate()));

      lotteryData.setCode(code);
      String openCode =
          returnHungData.getPoint1() + "," + returnHungData.getPoint2() + "," + returnHungData
              .getPoint3() + "," + returnHungData.getPoint4()
              + "," + returnHungData.getPoint5() + "," + returnHungData.getPoint6() + ","
              + returnHungData.getPoint7() + "," + returnHungData.getPoint8()
              + "," + returnHungData.getPoint9() + "," + returnHungData.getPoint10() + ","
              + returnHungData.getPoint11() + "," + returnHungData.getPoint12()
              + "," + returnHungData.getPoint13() + "," + returnHungData.getPoint14() + ","
              + returnHungData.getPoint15() + "," + returnHungData.getPoint16()
              + "," + returnHungData.getPoint17() + "," + returnHungData.getPoint18() + ","
              + returnHungData.getPoint19() + "," + returnHungData.getPoint20()
              + "," + returnHungData.getPoint21();
      openCode = openCode.substring(0, openCode.indexOf("null") - 1);
      if ("HF_CQKL10F".equals(code) || "HF_JXD11".equals(code) || "HF_GDKL10F".equals(code)
          || "HF_GDD11".equals(code) || "HF_SDD11".equals(code) || "HF_AHD11".equals(code)
          || "HF_TJKL10F".equals(code) || "HF_SHD11".equals(code) || "HF_BJPK10".equals(code)
          || "HF_XYFT".equals(code) || "MARK_SIX".equals(code)) {
        lotteryData.setOpencode(DataUtil.chuliCode(openCode));
      } else {
        lotteryData.setOpencode(DataUtil.chuliCodeRemove0(openCode));
      }
      lotterys.add(lotteryData);
    }
    return lotterys;
  }

  /**
   * caijingwang
   */
  public List<LotteryData> caijingwang(String url) throws IOException, ParseException {
    List<LotteryData> lotterys = new ArrayList<>();
    Document document = null;
    try {
      document = Jsoup.connect(url).userAgent(
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
          .get();
    } catch (Exception e) {
      throw e;
    }

    String qihao = null;
    Element bjkuai3 = document.getElementById("n_bjkuai3");
    if (bjkuai3 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = doShortQihao(bjkuai3);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_BJK3");
      String time = bjkuai3.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(bjkuai3));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_jlk3 = document.getElementById("n_jlk3");
    if (n_jlk3 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_jlk3);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_JLK3");
      String time = n_jlk3.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_jlk3));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element gxkuai3 = document.getElementById("n_gxkuai3");
    if (gxkuai3 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(gxkuai3);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_GXK3");
      String time = gxkuai3.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(gxkuai3));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element ahk3 = document.getElementById("n_ahk3");
    if (ahk3 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(ahk3);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_AHK3");
      String time = ahk3.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(ahk3));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element jsk3 = document.getElementById("n_jsk3");
    if (jsk3 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(jsk3);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_JSK3");
      String time = jsk3.getElementsByClass("time").text();
      String opencode = getOpenCode(jsk3);
      String[] str = opencode.split(",");
      Arrays.sort(str);
      opencode = str[0];
      for (int i = 1; i < str.length; i++) {
        opencode = opencode + "," + str[i];
      }
      lotteryData.setOpencode(opencode);
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element ah11x5 = document.getElementById("n_ah11x5");
    if (ah11x5 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(ah11x5);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_AHD11");
      String time = ah11x5.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(ah11x5));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_gd11x5 = document.getElementById("n_gd11x5");
    if (n_gd11x5 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_gd11x5);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_GDD11");
      String time = n_gd11x5.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_gd11x5));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element jx11x5 = document.getElementById("n_jx11x5");
    if (jx11x5 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(jx11x5);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_JXD11");
      String time = jx11x5.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(jx11x5));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_11ydj = document.getElementById("n_11ydj");
    if (n_11ydj != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_11ydj);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_SDD11");
      String time = n_11ydj.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_11ydj));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_sh11x5 = document.getElementById("n_sh11x5");
    if (n_sh11x5 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_sh11x5);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_SHD11");
      String time = n_sh11x5.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_sh11x5));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_gdklsf = document.getElementById("n_gdklsf");
    if (n_gdklsf != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_gdklsf);
      lotteryData.setExpect(getDoOpenCode(qihao));
      lotteryData.setCode("HF_GDKL10F");
      String time = n_gdklsf.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_gdklsf));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_cqklsf = document.getElementById("n_cqklsf");
    if (n_cqklsf != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_cqklsf);
      lotteryData.setExpect(getDoOpenCode(qihao));
      lotteryData.setCode("HF_CQKL10F");
      String time = n_cqklsf.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_cqklsf));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_cqssc = document.getElementById("n_cqssc");
    if (n_cqssc != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_cqssc);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_CQSSC");
      String time = n_cqssc.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_cqssc));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_tjssc = document.getElementById("n_tjssc");
    if (n_tjssc != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_tjssc);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_TJSSC");
      String time = n_tjssc.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_tjssc));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_xjssc = document.getElementById("n_xjssc");
    if (n_xjssc != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_xjssc);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_XJSSC");
      String time = n_xjssc.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_xjssc));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_bjpk10 = document.getElementById("n_bjpk10");
    if (n_bjpk10 != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = doShortQihao(n_bjpk10);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_BJPK10");
      String time = n_bjpk10.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_bjpk10));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    Element n_shssl = document.getElementById("n_shssl");
    if (n_shssl != null) {
      LotteryData lotteryData = new LotteryData();
      qihao = dolongQihao(n_shssl);
      lotteryData.setExpect(qihao);
      lotteryData.setCode("HF_SHSSL");
      String time = n_shssl.getElementsByClass("time").text();
      lotteryData.setOpencode(getOpenCode(n_shssl));
      String opentime = DataUtil.Data1ToShortString(new Date()) + " " + time;
      lotteryData.setOpentime(opentime);
      lotterys.add(lotteryData);
    }
    return lotterys;
  }

  /**
   * 彩票55
   */
  public List<LotteryData> caipiao55(String url) throws IOException, ParseException {
    Document document = Jsoup.connect(url).userAgent(
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
        .get();
    Element element = document.getElementById("_games_2");
    Elements elements = element.getElementsByTag("tr");
    List<LotteryData> lotteryDatas = new ArrayList<>();
    for (int i = 1; i < elements.size(); i++) {
      if (i == 1 || i == 3 || i == 5 || i == 10 || i == 18) {
        continue;
      }
      String kindcode = judgeKind(i);
      String qishu = elements.get(i).child(1).text();
      String opentime = elements.get(i).child(2).text();
      Elements ents = elements.get(i).getElementsByTag("span");
      String opencode = null;
      opencode = ents.get(0).text();
      if (opencode.indexOf("正") == 0) {
        continue;
      }
      LotteryData lotteryData = new LotteryData();
      if (i == 4 || i == 23 || i == 21 || i == 22) {
        opencode = anotherLotty(i, judgeUrl(i));
      } else {
        int size = ents.size();
        if (i == 6) {
          size = size - 1;
        }
        for (int j = 1; j < size; j++) {
          opencode = opencode + "," + ents.get(j).text();
        }
      }

      lotteryData.setCode(kindcode);
      lotteryData.setOpentime(opentime);
      lotteryData.setOpencode(opencode);
      lotteryData.setExpect(qishu);
      lotteryDatas.add(lotteryData);
    }
    return lotteryDatas;
  }

  /***
   * caipiao55
   * @return
   * @throws IOException
   * @throws ParseException
   */
  public LotteryData getfenghuangLotty(String url, String code) throws IOException, ParseException {
    String str = HttpRequest.sendGet(url, null);
    ObjectMapper objectMapper = new ObjectMapper();
    ReturnData500 data500s = objectMapper.readValue(str, ReturnData500.class);
    List<Data500> lists = data500s.getList();
    LotteryData lotteryData = new LotteryData();
    if (lists.size() == 0) {
      return null;
    }
    Data500 data500 = lists.get(0);
    String period = "";
    String opencode = "";
    if ("HF_BJPK10".equals(code) || "HF_XYFT".equals(code) || "HF_GDKL10F".equals(code)
        || "HF_JXD11".equals(code) || "HF_SDD11".equals(code) || "HF_SHD11".equals(code)
        || "HF_GDD11".equals(code) || "MARK_SIX".equals(code)) {
      opencode = DataUtil.chuliCode(data500.getResult());
    } else {
      opencode = data500.getResult();
    }
    if ("HF_XJSSC".equals(code) || "HF_GDKL10F".equals(code)) {
      period = getDoOpenCode(data500.getPeriod());
    } else {
      period = data500.getPeriod();
    }
    lotteryData.setExpect(period);
    lotteryData.setOpencode(opencode);
    lotteryData.setOpentime(data500.getDate() + ":00");
    return lotteryData;
  }

  public String anotherLotty(int a, String url) throws IOException, ParseException {
    Document document = Jsoup.connect(url).userAgent(
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
        .get();
    Elements elements = document.getElementsByClass("historycode");
    int b;
    if (a == 4) {
      b = 190;
    } else {
      b = 57;
    }
    String opencode = elements.get(b).text();

    if (a == 4) {
      for (int i = b + 1; i < 200; i++) {
        opencode = opencode + "," + elements.get(i).text();
      }
      opencode = DataUtil.chuliCode(opencode);
    } else {
      for (int i = b + 1; i < 60; i++) {
        opencode = opencode + "," + elements.get(i).text();
      }
    }
    return opencode;
  }

  public LotteryData c5gcpLotty(String url, String code) throws IOException, ParseException {
    Document document = Jsoup.connect(url).userAgent(
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
        .get();
    Element element = document.getElementById("draw_list");
    Elements elements = element.getElementsByTag("tr");

    Element ent = elements.get(1);
    Elements eles = ent.getElementsByTag("td");
    String opentime = eles.get(0).text() + " " + eles.get(1).text();
    String expect = eles.get(2).text();
    Elements elemens = eles.get(3).getElementsByClass("ball_1");
    String opencode = elemens.get(0).text();
    if ("MARK_SIX".equals(code)) {
      Elements elemen1 = eles.get(3).getElementsByTag("span");
      for (int j = 2; j < elemen1.size(); j++) {
        opencode = opencode + "," + elemen1.get(j).text();
      }
    } else {
      for (int j = 1; j < elemens.size(); j++) {
        opencode = opencode + "," + elemens.get(j).text();
      }
    }
    LotteryData lotteryData = new LotteryData();
    lotteryData.setOpentime(opentime);
    lotteryData.setOpencode(opencode);
    lotteryData.setExpect(expect);
    return lotteryData;
  }

  public List<LotteryData> caipiaoqq(String url) throws IOException, ParseException {
    String str = HttpRequest.sendGet(url, null);
    ObjectMapper objectMapper = new ObjectMapper();
    List<Object> list = new GsonJsonParser().parseList(str);
    List<LotteryData> lotteryDatas = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
      String str1 = JSONObject.toJSONString(list.get(i));
      LotteryData lotteryData = new LotteryData();
      QuanqiuData quanqiuData = objectMapper.readValue(str1, QuanqiuData.class);
      if (quanqiuData.getOpenStatus() == false) {
        continue;
      }
      if (judgeqqKind(quanqiuData.getGameUniqueId())) {
        continue;
      }
      lotteryData.setExpect(String.valueOf(quanqiuData.getUniqueIssueNumber()));
      lotteryData.setOpencode(quanqiuData.getOpenCode());
      lotteryData.setOpentime(DataUtil.Data1ToString(quanqiuData.getOpenTime()));
      lotteryData.setCode(quanqiuData.getGameUniqueId());
      lotteryDatas.add(lotteryData);
    }
    return lotteryDatas;
  }

  /***
   * 乐8彩票
   * @return
   * @throws IOException
   * @throws ParseException
   */
  public List<LotteryData> getlebaLotty(String url, String code) throws IOException, ParseException {
    String str = HttpRequest.sendGet(url, null);
    ObjectMapper objectMapper = new ObjectMapper();
    LebadataList list = objectMapper.readValue(str,LebadataList.class);
    List<LebaData> lists = list.getList();
    List<LotteryData> lotteryDatas = new ArrayList<>();
    if(lists.size()==0){
      return null;
    }
    for(LebaData lebaData:lists){
      LotteryData lotteryData=new LotteryData();
      if("HF_GDKL10F".equals(code)||"HF_XJSSC".equals(code)){
        lotteryData.setExpect(getDoOpenCode(lebaData.getPeriod()));
      }else if ("PL3".equals(code)){
        lotteryData.setExpect("20"+lebaData.getPeriod());
      }else{
        lotteryData.setExpect(lebaData.getPeriod());
      }
      lotteryData.setOpentime(lebaData.getDate()+":00");
      if("HF_BJPK10".equals(code)||"MARK_SIX".equals(code)||"HF_GDKL10F".equals(code)||"HF_GDD11".equals(code)||"HF_SDD11".equals(code)||"HF_JXD11".equals(code)||"HF_SHD11".equals(code)||"HF_XYFT".equals(code)){
        lotteryData.setOpencode(DataUtil.chuliCode(lebaData.getResult()));
      } else if("PL3".equals(code)){
        lotteryData.setOpencode(lebaData.getResult().substring(0,5));
      }else{
        lotteryData.setOpencode(lebaData.getResult());
      }
      lotteryDatas.add(lotteryData);
    }
    return lotteryDatas;
  }

  public String doShortQihao(Element element) {
    String qihao = element.getElementsByClass("qihao").text().replaceAll("期", "");
    return qihao;
  }

  public String dolongQihao(Element element) throws ParseException {
    String qihao =
        Data1ToMorShortString(new Date()) + "" + element.getElementsByClass("qihao").text()
            .replaceAll("期", "");
    return qihao;
  }

  public String Data1ToMorShortString(Date str) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    String time = format.format(str);

    return time;
  }

  public String getOpenCode(Element element) {
    String opencode = element.getElementsByTag("input").get(0).val();
    int a = element.getElementsByTag("input").size();
    for (int i = 1; i < a; i++) {
      opencode = opencode + "," + element.getElementsByTag("input").get(i).val();
    }
    return opencode;
  }

  public String getDoOpenCode(String code) {

    StringBuilder sb = new StringBuilder(code);
    sb.insert(code.length() - 2, "0");
    return sb.toString();
  }

  public String judgeKind(int i) {
    String kindcode = "";
    switch (i) {
      case 2:
        kindcode = "HF_CQSSC";
        break;
      case 4:
        kindcode = "HF_BJPK10";
        break;
      case 6:
        kindcode = "HF_BJ28";
        break;
      case 7:
        kindcode = "MARK_SIX";
        break;
      case 8:
        kindcode = "HF_XYFT";
        break;
      case 9:
        kindcode = "HF_GDKL10F";
        break;
      case 11:
        kindcode = "HF_SHSSL";
        break;
      case 12:
        kindcode = "HF_TJSSC";
        break;
      case 13:
        kindcode = "HF_XJSSC";
        break;
      case 14:
        kindcode = "HF_SDD11";
        break;
      case 15:
        kindcode = "HF_SHD11";
        break;
      case 16:
        kindcode = "HF_JXD11";
        break;
      case 17:
        kindcode = "HF_GDD11";
        break;
      case 19:
        kindcode = "X3D";
        break;
      case 20:
        kindcode = "PL3";
        break;
      case 21:
        kindcode = "HF_AHK3";
        break;
      case 22:
        kindcode = "HF_JSK3";
        break;
      case 23:
        kindcode = "HF_GXK3";
        break;
    }
    return kindcode;
  }

  public String judgeUrl(int i) {
    String url = "";
    switch (i) {
      case 4:
        url = "https://www.cp55067.com/common/trend/9?size=20";
        break;
      case 21:
        url = "https://www.cp55067.com/common/trend/11?size=20";
        break;
      case 22:
        url = "https://www.cp55067.com/common/trend/10?size=20";
        break;
      case 23:
        url = "https://www.cp55067.com/common/trend/17?size=20";
        break;
    }
    return url;
  }

  public Boolean judgeqqKind(String code) {
    Boolean flag = false;
    switch (code) {
      case "HF_XYSM":
      case "HF_LFSSC":
      case "HF_LFPK10":
      case "HF_LFKLPK":
      case "HF_LF28":
        flag = true;
        break;
    }
    return flag;
  }
}
